#ifndef ITEMSORTMODEL_H
#define ITEMSORTMODEL_H

#include <QSortFilterProxyModel>
#include <QPersistentModelIndex>
#include <QHash>
#include <QObject>
#include <QStringList>

#include "tray-icon-items-model.h"

class ItemSortModel : public QSortFilterProxyModel
{
    Q_OBJECT
public:
    explicit ItemSortModel(QObject *parent = nullptr);
    Q_INVOKABLE void setSourceModel(QAbstractItemModel *sourceModel) override;
    QModelIndex index(int row, int column, const QModelIndex &parent) const override;
    QVariant data(const QModelIndex &index, int role) const override;
    QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
    QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
    int rowCount(const QModelIndex &parent) const override;

    Q_INVOKABLE void setOrder(const QModelIndex &index, int order);
//    Q_INVOKABLE void addFixed(const QString &desktopFile, int order);
    Q_INVOKABLE void activate(const int &index);
    Q_INVOKABLE void contextMenu(const int &index);

protected:
    bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;

private Q_SLOTS:
    void onRowRemoved(const QModelIndex &parent, int first, int last);
    void onRowInsert(const QModelIndex &parent, int first, int last);

private:
    void initOrderData();

    QHash<QPersistentModelIndex, int> m_order;
    StatusNotifierModel *m_sourceModel = nullptr;

};

#endif // ITEMSORTMODEL_H
